package template

type IOtp interface {
	genRandomOTP(int) string
	saveOTPCache(string)
	getMessage(string) string
	sendNotification(string) error
}

type OtpMember struct {
	iOtp IOtp
}

// // 由xx组装
func (o *OtpMember) genAndSendOTP(otpLength int) error {
	otp := o.iOtp.genRandomOTP(otpLength)
	o.iOtp.saveOTPCache(otp)
	message := o.iOtp.getMessage(otp)
	return o.iOtp.sendNotification(message)

}

type OtpArgs struct {
}

func (o *OtpArgs) genAndSendOTP(iOtp IOtp, otpLength int) error {
	otp := iOtp.genRandomOTP(otpLength)
	iOtp.saveOTPCache(otp)
	message := iOtp.getMessage(otp)
	return iOtp.sendNotification(message)
}
